home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / ZIGOTO.CPP < prev    next >
C/C++ Source or Header  |  1993-08-02  |  6KB  |  196 lines

  1. //----------------------------------------------------------------------------
  2. //                            MODULE DESCRIPTION
  3. //
  4. //  Module:    zigoto.cpp
  5. //   Title:    9 Digit ZIP Disc Interface
  6. //  Notice:    John M. Weeder
  7. //                 Copyright (c) 1993. All rights reserved.
  8. //             This module contains proprietary information and should be 
  9. //                treated as confidential.
  10. //
  11. //----------------------------------------------------------------------------
  12. //                           MAINTENANCE HISTORY
  13. //
  14. // $Workfile$
  15. // $Revision$
  16. //   $Author$
  17. //     $Date$
  18. //      $Log$    
  19. //
  20. //----------------------------------------------------------------------------
  21. //                             MODULE NARRATIVE
  22. //
  23. //    This module contains code for the class ZI_GOTO.
  24. //
  25. //    The code in this module may be written in C++ or C.
  26. //
  27. //    This module is portable to:
  28. //        DOS 3.X+
  29. //        MS Windows 3.X+
  30. //        OS/2 2.X+
  31. //        OS/2 2.0 PM
  32. //
  33. //    The following compilers are supported:
  34. //        MSC 6.0A
  35. //        MSC/C++ 7.0
  36. //        Borland C++ 3.1 for DOS
  37. //        Borland C++ 1.0 for OS/2 2.X
  38. //
  39. //----------------------------------------------------------------------------
  40. #include <zi.hpp>
  41. #define USE_WIN_GOTO
  42. #if OS_DOS
  43. #include <zid.hpp>
  44. #elif OS_WINDOWS
  45. #include <ziw.hpp>
  46. #else
  47. #include <zio.hpp>
  48. #endif
  49.  
  50.  
  51. //----------------------------------------------------------------------------
  52. //   Description:    Default constructor
  53. //    Parameters:
  54. //       Returns:    
  55. //----------------------------------------------------------------------------
  56. FN_M ZI_GOTO::ZI_GOTO(FIELDID _fid, LONG _lMax, LONG _lMin, LONG _lDft)
  57. : ZN_WINDOW("WIN_GOTO", ZN_LOAD_CENTER|ZN_LOAD_NO_SHOW)
  58. {
  59.     ZI_GOTO::Initialize(CL_INIT_CLASS);
  60.     Assert(_fid);
  61.     fid = _fid;
  62.     lMin = MAX(_lMin, 0);
  63.     lMax = MAX(_lMax, 0);
  64.     lDft = _lDft;
  65.     if (lMin > lMax)
  66.         lMin = lMax;
  67.     if (lDft >= 0)
  68.         lDft = MAX(MIN(lMax, lDft), lMin);
  69.     Setup();
  70. }
  71.  
  72.  
  73. //----------------------------------------------------------------------------
  74. //   Description:    Destructor
  75. //    Parameters:
  76. //       Returns:    
  77. //----------------------------------------------------------------------------
  78. FN_M ZI_GOTO::~ZI_GOTO()
  79. {
  80.     ZI_GOTO::Destroy(FALSE);
  81.     Terminate();
  82. }
  83.  
  84.  
  85. //----------------------------------------------------------------------------
  86. //   Description:    Destroy object. Free any resources used by object.
  87. //                          Normally called by destructor.
  88. //                        Should allow multiple calls from various classes.
  89. //                        A class should almost always re-init its variables when 
  90. //                        it is destroyed to prevent accidents.
  91. //    Parameters:    fDestroyAll        Destroy parents also?
  92. //                                            Default is TRUE.
  93. //       Returns:    TRUE if successful.
  94. //----------------------------------------------------------------------------
  95. BOOL FN_M ZI_GOTO::Destroy(BOOL fDestroyAll)
  96. {
  97.     ZI_GOTO::Initialize(CL_INIT_CLASS_VARS);
  98.     if (fDestroyAll)                            // Destroy parent.
  99.         ZI_GOTO_PARENT::Destroy(fDestroyAll);
  100.     return TRUE;
  101. }
  102.  
  103.  
  104. //----------------------------------------------------------------------------
  105. //   Description:    Default constructor
  106. //    Parameters:
  107. //       Returns:    
  108. //----------------------------------------------------------------------------
  109. BOOL FN_M ZI_GOTO::Goto(FIELDID _fid, LONG _lMax, LONG _lMin, LONG _lDft)
  110. {
  111.    PZI_GOTO pzi_goto = new ZI_GOTO(_fid, _lMax, _lMin, _lDft);
  112.     if (pzi_goto == NULL)
  113.         return _ErrorNoMem();
  114.     else if (pzi_goto->IsValid())
  115.         {
  116.       pzi_goto->Show();
  117.         return TRUE;
  118.         }
  119.     return FALSE;
  120. }
  121.  
  122.  
  123. //----------------------------------------------------------------------------
  124. //   Description:    Initialize object. 
  125. //                          Normally called by constructor.
  126. //                        Should allow multiple calls from various classes.
  127. //    Parameters:    sInit        Initialization code. May be one of the following:
  128. //                                        CL_INIT_CLASS            Reset class variables and
  129. //                                                                    and dynamic allocations for
  130. //                                                                    this class only.
  131. //                                        CL_INIT_CLASS_VARS    Reset class variables for
  132. //                                                                    this class only.
  133. //                                        CL_INIT_VARS            Reset class variables for
  134. //                                                                    this class only.
  135. //                                        CL_INIT_ALL                Initialize class and all 
  136. //                                                                    parent class, including
  137. //                                                                    dynamic memory allocation.
  138. //                                    Default is CL_INIT_ALL
  139. //       Returns:    TRUE if successful.
  140. //----------------------------------------------------------------------------
  141. BOOL FN_M ZI_GOTO::Initialize(SHORT sInit)
  142. {
  143.     if (sInit == CL_INIT_VARS || sInit == CL_INIT_ALL)
  144.         ZI_GOTO_PARENT::Initialize(sInit);
  145.     return TRUE;
  146. }
  147.  
  148. //----------------------------------------------------------------------------
  149. //   Description:    Event monitor function.
  150. //    Parameters:    sEvent        Event code
  151. //                        pv1            Data pointer 1
  152. //                        pv2            Data pointer 2
  153. //       Returns:    Event code
  154. //----------------------------------------------------------------------------
  155. ZN_MSG FN_M ZI_GOTO::User(ZN_MSG msg, PVOID, PVOID)
  156. {
  157.     switch (msg)
  158.         {
  159.         case ZN_MSG_INIT:
  160.             {
  161.             CHAR szFormat[120];
  162.  
  163.             sprintf(szFormat, "(%ld..%ld)", lMin, lMax);
  164.             SetString(FID(STR_RANGE), szFormat);
  165.             if (lDft >= 0)
  166.                 SetNumber(FID(STR_GOTO), lDft);
  167.             }
  168.             return msg;
  169.  
  170.         case ZN_MSG_TERMINATE:
  171.             return msg;
  172.         }
  173.     if (IsError())                                // Error condition
  174.         return msg;
  175.     switch (msg)
  176.         {
  177.         case BUTTON_OK:
  178.             {
  179.             CHAR szBuf[40];
  180.             LONG lVal;
  181.             lVal = atol(GetNumber(FID(STR_GOTO), szBuf));
  182.             SendMessage(fid, ZI_MSG_GOTO, (PVOID)MIN(lMax, MAX(lVal, lMin)));
  183.             Close();
  184.             }
  185.             break;
  186.  
  187.         case BUTTON_CANCEL:
  188.             Close();
  189.             break;
  190.         }
  191.     return msg;
  192. }
  193. //----------------------------------------------------------------------------
  194. //------------------------------- End of File --------------------------------
  195. //----------------------------------------------------------------------------
  196.